#ifndef MYSTRING_H_
#define MYSTRING_H_
#include <cstring>
#include <iostream>
using namespace std;

//重载运算符：+、+=、=、[]、>、<、>=、<=、==
class MyString{
friend ostream& operator << (ostream& out, const MyString& rhs);
private:
	char*		m_data;
public:
	int size() const { return strlen(this->m_data); }
	
	MyString(const char* _str = 0);
	//拷贝构造的声明
	MyString(const MyString& rhs);			//const 可选参数   &必选

	const char* data() const { return this->m_data; }

	//x = y = z;
	const MyString& operator = (const MyString& rhs);

	//+
	const MyString operator + (const MyString& rhs) const;
	MyString& operator += (const MyString& rhs);

	bool operator == (const MyString& rhs) const 
	{ return strcmp(this->m_data, rhs.m_data) == 0; }

	bool operator < (const MyString& rhs) const
	{ return strcmp(this->m_data, rhs.m_data) < 0; }

	//...

	bool operator >= (const MyString& rhs) const 
	{ return strcmp(this->m_data, rhs.m_data) >= 0; }

	bool operator != (const MyString& rhs) const
	{ return strcmp(this->m_data, rhs.m_data) != 0; }

	//const版本  用于const对象调用 
	const char operator [] (int index) const { return this->m_data[index]; }

	char& operator [] (int index) { return this->m_data[index]; }
	
	~MyString();
};


#endif
